package cn.neo.hhrpc.core.api;

import cn.neo.hhrpc.core.config.ConsumerConfigProperties;
import cn.neo.hhrpc.core.meta.InstanceMeta;
import lombok.Data;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
public class RpcContext {

    List<Filter> filters;

    Router<InstanceMeta> router;

    LoadBalancer<InstanceMeta> loadBalancer;

    private Map<String, String> parameters = new HashMap<>();

    private ConsumerConfigProperties consumerProperties;


    public String param(String key) {
        return parameters.get(key);
    }

    public static ThreadLocal<Map<String, String>> ContextParameters = ThreadLocal.withInitial(() -> new HashMap<>());

    public static void setContextParameters(String key, String value) {
        ContextParameters.get().put(key, value);
    }

    public static String getContextParameters(String key) {
        return ContextParameters.get().get(key);
    }

    public static void removeContextParameters(String key) {
        ContextParameters.get().remove(key);
    }

}
